from minisprite import Player, Enemy, Block

mapcfg = ((), # ignore 0
         (  # level 1
          (1, (0, 0)), # item (type, (node.x, node.y))
          (2, (4, 6)),
          (3, (2, 2)),
          (3, (2, 4)),
          (3, (2, 6)),
          (3, (4, 2)),
          ),
         )

class Map(object):
    HOME = 0
    PLAYER = 1
    ENEMY = 2
    BLOCK = 3
    GRID = 16
    XAXIS = 40
    YAXIS = 40
    def __init__(self, rawmap): # rawmap = (item1, item2...itemn)
        super(Map, self).__init__()
        self.player = []
        self.enemy = []
        self.block = []
        for item in rawmap:
            if item[0] == Map.PLAYER:
                self.player.append(Player(self.node2pixel(item[1]), self))
            elif item[0] == Map.ENEMY:
                self.enemy.append(Enemy(self.node2pixel(item[1]), self))
            elif item[0] == Map.BLOCK:
                self.block.append(Block(self.node2pixel(item[1]), self))
        self.all = self.player + self.enemy + self.block
    
    def get_simplemap(self):
        sm = []
        node = None
        for x in xrange(Map.XAXIS):
            sm.append([0] * Map.YAXIS)
        for spr in self.__all:
            node = self.pixel2node(spr.pos)
            sm[node[0], node[1]] = 1
            sm[node[0] + 1, node[1]] = 1
            sm[node[0], node[1] + 1] = 1
            sm[node[0] + 1, node[1] + 1] = 1
    
    def node2pixel(self, node):
        return (node[0] * Map.GRID, node[1] * Map.GRID)
    
    def pixel2node(self, pixel):
        return (pixel[0] // Map.GRID, pixel[1] // Map.GRID)






















